<?php
/**
 * This loads a user identity to the request so access can be determined
 */
class App_Plugin_IdentityLoader extends Zend_Controller_Plugin_Abstract {

   public function preDispatch(Zend_Controller_Request_Abstract $request) {
      //non-authed users are just anonymous users

      if(Zend_Auth::getInstance()->hasIdentity()) {
         //$user = Model_User::findById(Zend_Auth::getInstance()->getIdentity());
         $userModel = new Model_User();
         $user = $userModel->findOneBy('id', Zend_Auth::getInstance()->getIdentity());
      } else {
         $user = new Model_GuestUser();
         $session = new Zend_Session_Namespace('Default');
         $session->username = $user->getUserName();
      }
      $request->setParam('user', $user);
   }

}